package com.expense.app.admin.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.expense.app.admin.annotation.OpeLog;
import com.expense.app.admin.model.params.adminRole.AdminRoleDetailSaveParam;
import com.expense.app.admin.model.params.adminRole.AdminRoleListParam;
import com.expense.app.admin.model.params.adminRole.AdminRoleStatusParam;
import com.expense.app.admin.services.AdminRoleServ;
import com.expense.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/adminRole")
public class AdminRoleCtrl {
    private static final Log log = LogFactory.get();

    @Autowired
    AdminRoleServ adminRoleServ;

    @GetMapping("/all/availableList")
    public Result findAllList() {
        return Result.success(adminRoleServ.findAllList());
    }

    @GetMapping("")
    public Result findList(@Validated AdminRoleListParam param) {
        return Result.success(adminRoleServ.findList(param));
    }

    @GetMapping("/{id}")
    public Result findDetail (@Validated @PathVariable Long id) {
        return Result.success(adminRoleServ.findDetail(id));
    }

    @PostMapping("")
    @OpeLog(type = "角色管理",value = "保存角色信息")
    public Result saveOne(@Validated @RequestBody AdminRoleDetailSaveParam param) {
        return Result.success(adminRoleServ.saveOne(param));
    }

    @PutMapping("")
    @OpeLog(type = "角色管理",value = "更新角色信息")
    public Result updateOne(@Validated @RequestBody AdminRoleDetailSaveParam param) {
        return Result.success(adminRoleServ.saveOne(param));
    }

    @PutMapping("/status")
    @OpeLog(type = "角色管理",value = "更改角色状态")
    public Result updateStatus(@Validated @RequestBody AdminRoleStatusParam param) {
        return Result.success(adminRoleServ.updateStatus(param));
    }

    @DeleteMapping("/{id}")
    @OpeLog(type = "角色管理",value = "删除角色")
    public Result deleteOne(@Validated @PathVariable Long id) {
        return Result.success(adminRoleServ.deleteOne(id));
    }

}
